﻿using Li.DingTalk;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace DingTalkAgent.Web.Areas.mobile.Controllers
{
    public class homeController : Controller
    {


        // GET: mobile/a
        public ActionResult Index11()
        {
            return View();
        }
        [HttpPost]
        public ActionResult Index11(string url,string content="")
        {
            //https://oapi.dingtalk.com/robot/send?access_token=c6c4d40c4a307927f6f47c7cc820c0418a07aae3b727617f65618ccaebe832b8
            var result = Li.DingTalk.Model.Robot.RobotHandel.Noaction(new Li.DingTalk.Model.Robot.textMessage()
            {
                msgtype = "text",
                at = new Li.DingTalk.Model.Robot.atTarget() { atMobiles = new string[] { "" }, isAtAll = false },
                text = new Li.DingTalk.Model.Robot.contentText() { content =content }
            }, url);
            return Content("成功");
        }
        // GET: mobile/a
        public ActionResult Index()
       {
            //https://oapi.dingtalk.com/robot/send?access_token=c6c4d40c4a307927f6f47c7cc820c0418a07aae3b727617f65618ccaebe832b8
           var result= Li.DingTalk.Model.Robot.RobotHandel.Noaction(new Li.DingTalk.Model.Robot.textMessage() {
                msgtype="text",
                at=new Li.DingTalk.Model.Robot.atTarget() { atMobiles=new string[] { },isAtAll=false},
                text=new Li.DingTalk.Model.Robot.contentText() { content= @"### 2017-11-30销售情况 ###
------------------------------
昆明北市区分店
今日：销售总额50000元，
昨日：销售总额46000元，
环比：上升4000元
本月销售总额：800000元
------------------------------
昆明五化区分店
今日：销售总额40000元，
昨日：销售总额43000元，
环比：下降3000元
本月销售总额：800000元
------------------------------
昆明西山区分店
今日：销售总额30000元，
昨日：销售总额28000元，
环比：上升2000元
本月销售总额：800000元

## 今日销售冠军：昆明北市区分店 ##
" }
            }, "https://oapi.dingtalk.com/robot/send?access_token=c6c4d40c4a307927f6f47c7cc820c0418a07aae3b727617f65618ccaebe832b8");
            return View();
        }


        public ActionResult Index1()
        {
            //https://oapi.dingtalk.com/robot/send?access_token=c6c4d40c4a307927f6f47c7cc820c0418a07aae3b727617f65618ccaebe832b8
            var result = Li.DingTalk.Model.Robot.RobotHandel.Noaction(new Li.DingTalk.Model.Robot.textMessage()
            {
                msgtype = "text",
                at = new Li.DingTalk.Model.Robot.atTarget() { atMobiles = new string[] { }, isAtAll = false },
                text = new Li.DingTalk.Model.Robot.contentText() { content = @"### 昨日网店经营情况 ###
------------------------------
天猫旗舰店
今日：
销售总额670000元，
订单数：3241单
新客户：120位
昨日：
销售总额620000元，
订单数：3200单
新客户：100位
本月销售总额：34000000元
------------------------------
天猫旗舰店
今日：
销售总额370000元，
订单数：5241单
新客户：70位
昨日：
销售总额320000元，
订单数：3200单
新客户：40位
本月销售总额：34000000元
------------------------------
总计：
销售总额1070000元，
订单数：5241单
新客户：180位
" }
            }, "https://oapi.dingtalk.com/robot/send?access_token=c6c4d40c4a307927f6f47c7cc820c0418a07aae3b727617f65618ccaebe832b8");
            return Content("");
        }
        // GET: mobile/a
        public ActionResult Index2()
        {
            var result = Li.DingTalk.Model.Robot.RobotHandel.Noaction(new Li.DingTalk.Model.Robot.ActionCard()
            {
                msgtype = "actionCard",
                actionCard = new Li.DingTalk.Model.Robot.actionC() {
                    title = "库存不足提醒",
                    text = @"### 库存不足提醒
伊利牛奶剩余:10箱，昨日售出：2箱
百事可乐剩余:10箱，昨日售出：2箱
辣条剩余:100包，昨日售出：19包
五粮液剩余:1箱，昨日售出：2瓶

## 以上商品库存剩余超过警戒，请采购部门知晓",
                    hideAvatar="0",
                    btnOrientation="0",
                    btns=new List<Li.DingTalk.Model.Robot.btns>() { new Li.DingTalk.Model.Robot.btns() { title = "已知晓",actionURL="#"} }
                }
               
            }, "https://oapi.dingtalk.com/robot/send?access_token=c6c4d40c4a307927f6f47c7cc820c0418a07aae3b727617f65618ccaebe832b8");
            return Content("");
        }

        // GET: mobile/a
        public ActionResult Index3()
        {
            var result = Li.DingTalk.Model.Robot.RobotHandel.Noaction(new Li.DingTalk.Model.Robot.ActionCard()
            {
                msgtype = "actionCard",
                actionCard = new Li.DingTalk.Model.Robot.actionC()
                {
                    text = @"### 危险提醒
目前水位:120cm，标准水位：100cm
水密度比:1.3，  标准密度：1.0
浑浊度:1.25，   标准指标：1.0

## 值班部门12点测试报告，请工程部门快速解决!",
                    hideAvatar = "0",
                    btnOrientation = "1",
                    btns = new List<Li.DingTalk.Model.Robot.btns>() { new Li.DingTalk.Model.Robot.btns() { title = "忽略", actionURL = "#" },new Li.DingTalk.Model.Robot.btns() { title = "已解决", actionURL = "#" } }
                }

            }, "https://oapi.dingtalk.com/robot/send?access_token=c6c4d40c4a307927f6f47c7cc820c0418a07aae3b727617f65618ccaebe832b8");
            return Content("");
        }

        // GET: mobile/a
        public ActionResult Index4()
        {
            var result = Li.DingTalk.Model.Robot.RobotHandel.Noaction(new Li.DingTalk.Model.Robot.ActionCard()
            {
                msgtype = "actionCard",
                actionCard = new Li.DingTalk.Model.Robot.actionC()
                {
                    title = "祝习大大 生日快乐",
                    text = @"![screenshot](https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1512023279063&di=56bbe9480a1518f71d70d240de8d777f&imgtype=0&src=http%3A%2F%2Fuploadfile.bizhizu.cn%2F2015%2F0206%2F20150206032722112.jpg) 
 ### 习大大 生日快乐 
 各位小伙伴大家好，今天是 “习大大” 同学的生日哦~~，让我们一起祝他生日快乐，各种鲜花、掌声和红包走一波~",
                    hideAvatar = "0",
                    btnOrientation = "1",
                    btns = new List<Li.DingTalk.Model.Robot.btns>() { new Li.DingTalk.Model.Robot.btns() { title = "穷逼略过", actionURL = "#" }, new Li.DingTalk.Model.Robot.btns() { title = "土豪打赏", actionURL = "#" } }
                }

            }, "https://oapi.dingtalk.com/robot/send?access_token=c6c4d40c4a307927f6f47c7cc820c0418a07aae3b727617f65618ccaebe832b8");
            return Content("");
        }

        // GET: mobile/a
        public ActionResult Index5()
        {
            var result = Li.DingTalk.Model.Robot.RobotHandel.Noaction(new Li.DingTalk.Model.Robot.ActionCard()
            {
                msgtype = "actionCard",
                actionCard = new Li.DingTalk.Model.Robot.actionC()
                {
                    title = "2017-12-10日 销售报表",
                    text = @"![screenshot](http://pic.qiantucdn.com/58pic/26/12/07/58c1b16911025_1024.jpg!/fw/780/watermark/url/L3dhdGVybWFyay12MS40LnBuZw==/align/center) 
 ### 2017-12-10日 销售报表 
 恭喜天猫旗舰店为本日销售冠军，已经连续20日获得销售冠军,继续努力~",
                    hideAvatar = "0",
                    btnOrientation = "1",
                    btns = new List<Li.DingTalk.Model.Robot.btns>() { new Li.DingTalk.Model.Robot.btns() { title = "查看详细", actionURL = "#" } }
                }

            }, "https://oapi.dingtalk.com/robot/send?access_token=c6c4d40c4a307927f6f47c7cc820c0418a07aae3b727617f65618ccaebe832b8");
            return Content("");
        }


        public ActionResult Index6()
        {

            string openUrl = "https://oapi.dingtalk.com/message/send";
            string userId = "manager5443";
            string JsonString = "{\"touser\":\"" + userId + "\",\"toparty\":\"\",\"agentid\":\"" + ConfigHelper.getagentid() + "\",\"msgtype\": \"oa\",\"oa\": {\"message_url\": \"" + openUrl + "\",\"head\": {\"bgcolor\": \"FFBBBBBB\",\"text\": \"文件柜\"},\"body\": {\"title\": \"文件分享-" + "\",\"form\": [{\"key\": \"分享者:\",\"value\": \""+ "\"}],\"content\": \""  + "给你分享了一个文件快去查看吧!\",\"image\": \"" + ConfigHelper.getUrlRoot() + "/skin/sharex.png\"}}}";// "{\"touser\":\"07114663388908416\",\"toparty\":\"\",\"agentid\":\"75455225\",\"msgtype\": \"link\",\"link\": {\"messageUrl\": \"http://www.baidu.com\",\"picUrl\":\"@lALOACZwe2Rk\",\"title\": \"测试fffffff\",\"text\": \"测试fffffff\"}}";//AgentID    :75455224 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               //string JsonString = "{\"touser\":\"" + userId + "\",\"toparty\":\"\",\"agentid\":\"" + ConfigHelper.getagentid() + "\",\"msgtype\": \"link\",\"link\": {\"messageUrl\": \"" + openUrl + "\",\"picUrl\":\"\",\"title\": \"文件分享\",\"text\": \"" + _wap_account.UserName + "给你分享了一个文件快去查看吧!\"}}";
            string resultJson = RequestHelper.Post(openUrl, JsonString.Replace("'", "\""));

            return Content("");
        }
    }
}